import storage from '../storage.js'
const session = "sessionStorage"
export default {
    state: {
        userInfo: storage.getValue('userInfo', session),
        token: storage.getValue('token', session),
        isLogin: storage.getValue('isLogin', session)
    },
    getters: {
        // 计算属性
        getToken: (state) => {
            return state.token;
        },
    },
    mutations: {
        // 设置用户信息
        setUserInfo(state, userInfo) {
            state.userInfo = userInfo;
            storage.setValue('userInfo', userInfo, session);
        },
        setLogin(state, isLogin) {
            console.log("setLogin", isLogin);
            state.isLogin = isLogin;
            storage.setValue('isLogin', isLogin, session);
        },

        // 设置token
        setToken(state, token) {
            state.token = token;
            storage.setValue('token', token,session);
        },
        // 清除用户信息
        cleanUserInfo(state) {
            state.userInfo = "";
            storage.cleanValue('userInfo',session);
        },
        // 清除token
        cleanToken(state) {
            state.token = '';
            storage.cleanValue('token',session);
        },
        // 清除login
        cleanLogin(state) {
            state.isLogin = false;
            storage.cleanValue('isLogin',session);
        },
    },
    actions: {},
}
